using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
//using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;
using TDBaseDataLibrary;

namespace TDEngineLibrary
{
    public class LevelSystem : TDBaseScene
    {
        TDLevelList m_list;
        public LevelSystem(Game game):base(game)
        {
            m_CurLevel = new TDLevel(game);
            m_nLevelIndex = -1;
        }
        ~LevelSystem()
        {
        }
        public int      m_nLevelIndex;
        public TDLevel  m_CurLevel;
        public bool InitLevelSystem(ContentManager Content,String szLevelsConfig)
        {
            m_list = Content.Load<TDLevelList>(szLevelsConfig);
            return false;
        }
        public bool LoadFirstLevel(ContentManager Content)
        {
            m_nLevelIndex = 0;
            return LoadLevel(Content, m_nLevelIndex);
        }
        public bool LoadNextLevel(ContentManager Content)
        {
            m_nLevelIndex++;
            return LoadLevel(Content, m_nLevelIndex);
        }
        public bool LoadLevel(ContentManager Content,int nIndex)
        {
            return m_CurLevel.LoadLevel(Content, m_list.LevelList[nIndex].levelconfig);
        }
        public override void LoadContent(ContentManager Content)
        {
            Enemy.LoadContent(Content);
            m_CurLevel.LoadContent(Content);
        }
        public override void UnloadContent()
        {
        }
        public override int Update(GraphicsDeviceManager graphics, GameTime gameTime)
        {
            return m_CurLevel.Update(graphics, gameTime);
        }
        public override void Draw(GraphicsDeviceManager graphics, GameTime gameTime, SpriteBatch spriteBatch, int xOffset, int yOffset, float fScale)
        {
            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
            m_CurLevel.Draw(graphics,gameTime, spriteBatch, xOffset, yOffset,fScale);
            spriteBatch.End();
        }
    }
}
